﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Biblioteca.fachada;
using Biblioteca.classesBasicas.equipamento;
using Desktop.views.cruds.crudsEquipamento.crudCilindrio;

namespace Desktop.views.cruds.crudsEquipamento.crudCilindro
{
    public partial class MenuCilindro : Form
    {
        private MenuEquipamento menuEquipamento;
        private Fachada fachada = new Fachada();
        private List<Cilindro> listaCilindro;
        private Cilindro cilindro = new Cilindro();
        

        public MenuCilindro(MenuEquipamento menuEquipamento)
        {
            this.menuEquipamento = menuEquipamento;
            menuEquipamento.Hide();

            InitializeComponent();
        }

        private void buttonCadastrar_Click(object sender, EventArgs e)
        {
            CadastroCilindro cadastroCilindro = new CadastroCilindro(this);
            cadastroCilindro.ShowDialog();
        }

        private void buttonSair_Click(object sender, EventArgs e)
        {
            menuEquipamento.Show();
            this.Dispose();
        }

        private void MenuCilindro_FormClosed(object sender, FormClosedEventArgs e)
        {
            menuEquipamento.Show();
            this.Dispose();
        }

        private void MenuCilindro_Load(object sender, EventArgs e)
        {
            this.carregarGridViewCilindro();
        }


        private void dataGridViewCilindro_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                DataGridViewRow row = this.dataGridViewCilindro.Rows[e.RowIndex];

                cilindro.Id = row.Cells[0].Value.ToString();
                cilindro.Nome = row.Cells[1].Value.ToString();
                cilindro.Tipo = row.Cells[2].Value.ToString();
                cilindro.Marca = row.Cells[3].Value.ToString();
                cilindro.Valor = row.Cells[4].Value.ToString();

                AlterarRemoverCilindro alterar = new AlterarRemoverCilindro(this, cilindro);
                alterar.ShowDialog();
            }
        }


        public void carregarGridViewCilindro()
        {
            listaCilindro = fachada.listarCilindro();

            DataGridViewCellStyle columnHeaderStyle =
            new DataGridViewCellStyle();
            columnHeaderStyle.BackColor = Color.Aqua;
            columnHeaderStyle.Font =
                new Font("Verdana", 10, FontStyle.Bold);
            this.dataGridViewCilindro.ColumnHeadersDefaultCellStyle =
                columnHeaderStyle;

            dataGridViewCilindro.DataSource = listaCilindro;

            this.dataGridViewCilindro.Columns[0].HeaderText = "ID";
            this.dataGridViewCilindro.Columns[1].HeaderText = "NOME";
            this.dataGridViewCilindro.Columns[2].HeaderText = "TIPO";
            this.dataGridViewCilindro.Columns[3].HeaderText = "MARCA";
            this.dataGridViewCilindro.Columns[4].HeaderText = "VALOR";
        }

    }
}
